package com.netty.zhanglong.fourth.example;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;

/**
 * Description:
 *
 * @author: StriverFeng
 * @date: 2018-9-27
 * Details:
 */
public class MyServerHanler extends ChannelInboundHandlerAdapter {


    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if (evt instanceof IdleStateEvent){
            IdleStateEvent event= (IdleStateEvent) evt;
            String eventType=null;
            switch (event.state()){
                case READER_IDLE:
                    eventType="reader 空闲";
                    break;
                case WRITER_IDLE:
                    eventType="writer 空闲";
                    break;
                case ALL_IDLE:
                    eventType="reader writer空闲";
                    break;
            }
            System.out.println(ctx.channel().remoteAddress()+"超时事件:  "+eventType);
            ctx.channel().close();

        }
    }
}
